package gateway

import (
	"context"
	"github.com/liserc/opensocket-server/pkg/config"
	"github.com/liserc/opensocket-server/tool/log"
)

type Config struct {
	Share     config.Share
	Discovery config.Discovery
	Gateway   config.Gateway
}

func Start(ctx context.Context, conf *Config) error {
	log.CInfo(ctx, "gateway server is initializing", "port", conf.Gateway.Websocket.Port,
		"rpc", conf.Gateway.RPC.Port, "prometheus", conf.Gateway.Prometheus.Port)

	webserver := NewWebServer(conf)
	hubServer := NewHubServer(conf, webserver)

	done := make(chan error)
	go func() {
		err := hubServer.Start(ctx)
		done <- err
	}()

	return webserver.Run(done)
}
